import java.util.Arrays;
import java.util.Scanner;


public class HW1PS2{
	public static void main(String[] arg){
Scanner sc = new Scanner(System.in);
        System.out.println("------------------------------------------");
        System.out.println("Create a List with Length: ");
        System.out.println("(Please Enter the length of list)");
        int init_length = sc.nextInt();
        
        int[] int_list = new int[init_length];
        System.out.println("List is Created!");

        
        
 
        int fill = 0; // variable fill to track the number of elements in this list. 
		int list_length = init_length;
        int option; // Scanner variable 
        
        
        // do while loop is needed to make sure this is execute at least once. 
		// initalized option with on assigned number might be 0, that will leads to no execution of the body of the loop 
        do{
        System.out.println("------------------------------------------");
        System.out.println("Option 1: Add Element");
        System.out.println("Option 2: Examine Length");
        System.out.println("Option 3: Print List");
        System.out.println("Option 0: End ");
        System.out.println("Please Enter the Option Num");
        option = sc.nextInt();
        switch(option){
		// add elemtent 
            case 1:  
                System.out.println("Enter the Number you want to add");
                int add_int = sc.nextInt();
                int_list[fill] = add_int;
                fill++; // update fill number 
				//System.out.println("Threshold number is "+ 0.8* list_length + " Now Filled number is" + fill);
				
                if (fill >= 0.8* list_length){
					//System.out.println("Threshold number is "+ 0.8* list_length);
                    int[] int_list2 = new int[(int)Math.round(list_length* 1.5)]; // speical accomadation for converting the type
					list_length = int_list2.length;
					System.out.println("New List Created ! ");
                    for (int i = 0; i < int_list.length; i++){
                        int_list2[i]=int_list[i];
                        
                    }   
					int_list = int_list2;
                }
                break;
		// Print length and filled number 
            case 2:
                System.out.println("List Length:" + int_list.length);
                System.out.println("Filled Length:" + fill);
                break;
		// Print list 
            case 3:
                System.out.println(Arrays.toString(int_list));
                break;
		// Quit 
            case 0:
				System.out.println("Good Bye! Have Fun! ");
                break;
            default:
                System.out.println("Unkown Commands");
                break;
        }
        
        }
        while (0 != option);
	}
}